<?php

namespace register\controller;

require_once("register/view/RegisterView.php");
require_once("register/model/RegisterModel.php");

class RegisterController {

	/**
	 * @var \register\view\RegisterView $view
	 */
	private $view;
	/**
	 * @var\register\model\RegisterModel $model
	 */
	private $model;

	/**
	 * initiate member variables
	 * @param registerviewRegisterView $view 
	 */
	public function __construct(\register\view\RegisterView $view, \common\model\BaseDAL $baseDAL) {
		$this->model = new \register\model\RegisterModel($baseDAL);
		$this->view = $view;
	}

	/**
	 * check if user is trying to registrate
	 * @return void
	 */
	public function runRegister() {
		if ($this->view->userRegistrating()) {
			try {
				$userData = $this->view->getUserData();
				$this->model->register($userData);
			} catch (\Exception $e) {
				$this->view->registerFail();
			}
		}
	}
}